package com.zhuiYun.project.api.appletshoppingcart.controller;

import com.zhuiYun.project.api.appletshoppingcart.model.AppletShoppingCartModel;
import com.zhuiYun.project.api.appletshoppingcart.service.AppletShoppingCartService;
import com.zhuiYun.project.api.handworkdiy.entity.HandworkDiy;
import com.zhuiYun.project.api.order.entity.Order;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lyp
 * @className AppletShoppingCartController
 * @description TODO
 * @date 2023/4/5 9:38
 */
@Slf4j
@Api(tags = "小程序购物车")
@RestController
@RequestMapping("/AppletShoppingCart")
@CrossOrigin
public class AppletShoppingCartController extends BaseController {

    @Autowired
    AppletShoppingCartService appletShoppingCartService;

    /**
     * @author lyp
     * @description 查询购物车内商品
     * @date 2023/4/5 9:44
     * @param typeId 按照日期分类的分类id
     * @return CommonResult
     */
    @ApiOperation(value = "用户购物车信息查询")
    @GetMapping("/selectShoppingCart")
    public CommonResult selectShoppingCart(Integer typeId,String type,Integer userId) throws CommonException {
        log.info("查询购物车信息");
        CommonResult commonResult = appletShoppingCartService.selectShoppingCart(typeId,type,userId);
        return commonResult;
    }

    /**
     * @author lyp
     * @description 根据用户id和物品id删除购物车内的商品
     * @date 2023/4/6 20:08
     * @param: id 物品id
     * @param: userId 用户id
     * @return CommonResult
     */
    @ApiOperation(value = "用户删除购物车内的商品")
    @PostMapping("/delItemsInShoppingCart")
    public CommonResult delItemsInShoppingCart(@RequestBody AppletShoppingCartModel appletShoppingCartModel) throws CommonException{
        log.info("用户id为"+appletShoppingCartModel.getUserId()+"删除了购物车内的商品");
        CommonResult commonResult = appletShoppingCartService.delItemsInShoppingCart(appletShoppingCartModel);
        return commonResult;
    }

    /**
     * @author lyp
     * @description 将购物车内的商品移入到我的个人收藏
     * @date 2023/4/7 9:38
     * @param appletShoppingCartModel
     * @return CommonResult
     */
    @ApiOperation(value = "将购物车内的商品移入到我的个人收藏")
    @PostMapping("/cartMoveIntoCollection")
    public CommonResult cartMoveIntoCollection(@RequestBody AppletShoppingCartModel appletShoppingCartModel) throws CommonException{
        log.info("用户id为"+appletShoppingCartModel.getUserId()+"将购物车商品移入了收藏");
        CommonResult commonResult = appletShoppingCartService.cartMoveIntoCollection(appletShoppingCartModel);
        return commonResult;
    }

    /**
     * @author lyp
     * @description 持久化用户购物车信息 例如 ：加了一个商品数量等
     * @date 2023/4/7 11:46
     * @param appletShoppingCartModel
     * @return CommonResult
     */
    @ApiOperation(value = "持久化用户购物车信息")
    @PostMapping("/persistingUserShoppingCartInfo")
    public CommonResult persistingUserShoppingCartInfo(@RequestBody AppletShoppingCartModel appletShoppingCartModel) throws CommonException{
        log.info("持久化用户购物车信息");
        CommonResult commonResult = appletShoppingCartService.persistingUserShoppingCartInfo(appletShoppingCartModel);
        return commonResult;
    }

    /**
     * @author lyp
     * @description 持久化用户选中商品
     * @date 2023/4/8 9:22
     * @param: appletShoppingCartModel
     * @return CommonResult
     */
    @ApiOperation(value = "持久化用户选中商品")
    @PostMapping("/persistingFlag")
    public CommonResult persistingFlag(@RequestBody AppletShoppingCartModel appletShoppingCartModel) throws CommonException{
        log.info("持久化用户选中商品");
        CommonResult commonResult = appletShoppingCartService.persistingFlag(appletShoppingCartModel);
        return commonResult;
    }

    /**
     * @author lyp
     * @description 用户结算购物车内的商品
     * @date 2023/4/10 11:36
     * @param
     * @return CommonResult
     */
    @ApiOperation(value = "用户结算购物车内的商品")
    @PostMapping("/closeAnAccount")
    public CommonResult closeAnAccount(@RequestBody List<AppletShoppingCartModel> comm, List<HandworkDiy> da) throws CommonException{
        return null;
    }

    /**
     * @author lyp
     * @description 用户结算购物车内的商品，进行商品查询
     * @date 2023/4/11 13:28
     * @param: userId 用户id
     * @return CommonResult
     */
    @ApiOperation(value = "用户结算购物车内的商品，进行商品查询")
    @GetMapping("/getShoppingCartInfo")
    public CommonResult getShoppingCartInfo(Integer userId) throws CommonException{
        log.info("用户结算购物车内的商品，进行商品查询");
        CommonResult shoppingCartInfo = appletShoppingCartService.getShoppingCartInfo(userId);
        return shoppingCartInfo;
    }

    /**
     * @author lyp
     * @description 用户结算购物车内的diy，进行diy查询
     * @date 2023/4/11 14:53
     * @param: userId 用户id
     * @return CommonResult
     */
    @ApiOperation(value = "用户结算购物车内的diy，进行diy查询")
    @GetMapping("/getShoppingCartInfoDiy")
    public CommonResult getShoppingCartInfoDiy(Integer userId) throws CommonException{
        log.info("用户结算购物车内的diy，进行diy查询");
        CommonResult shoppingCartInfoDiy = appletShoppingCartService.getShoppingCartInfoDiy(userId);
        return shoppingCartInfoDiy;
    }
    
    /**
     * @author lyp
     * @description 查询用户默认地址
     * @date 2023/4/14 9:02
     * @param userId
     * @return CommonResult
     */
    @ApiOperation(value = "查询用户地址")
    @GetMapping("/getUserAddress")
    public CommonResult getUserAddress(Integer userId) throws CommonException{
        log.info("查询用户地址");
        CommonResult userAddress = appletShoppingCartService.getUserAddress(userId);
        return userAddress;
    }
}
